package cn.wolfcode.shop.seckill.web.advice;

import cn.wolfcode.cloud.exception.BusinessException;
import cn.wolfcode.cloud.result.CodeMsg;
import cn.wolfcode.cloud.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GoodServerExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result handlerBusinessException(BusinessException businessException){
        CodeMsg codeMsg = businessException.getCodeMsg();
        Result result  = Result.error(codeMsg);
        return result;
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<Boolean> handlerException(Exception exception){
        Result<Boolean> result = Result.defaluterror();
        return result;
    }
}
